<template>
  <div>
    <el-row class="params">
      <el-button type="primary" @click="addShops">添加商家</el-button>
    </el-row>

    <el-table :data="listData" border highlight-current-row stripe style="width: 100%;margin-top: 20px">
      <el-table-column prop="sellerName" label="商家名称"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" @click="modShopsBtn(scope.row)">修改</el-button>
          <br>
          <el-button type="text" @click="open(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog type="text" title="填写商家信息" :modal-append-to-body="false" :visible.sync="dialogVisible" width="30%">
      <el-form>
        <el-form-item label="商家名称">
          <el-input v-model="sellerName"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
         <el-button @click="dialogVisible = false">取 消</el-button>
         <el-button type="primary" @click="dialogVisibleTrue">确 定</el-button>
       </span>
    </el-dialog>

    <el-dialog type="text" title="修改商家信息" :modal-append-to-body="false" :visible.sync="modShops" width="30%">
      <el-form>
        <el-form-item label="商家名称">
          <el-input v-model="sellerName"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
         <el-button @click="modShops = false">取 消</el-button>
         <el-button type="primary" @click="modShopsTrue">确 定</el-button>
       </span>
    </el-dialog>

    <el-pagination
      background
      @current-change="jump"
      layout="total, prev, pager, next, jumper"
      :pageSize=15
      :total="total">
    </el-pagination>

  </div>
</template>

<script>
  import {ajax, sellerList, addSeller, modifySellerName, deleteSeller} from "../../data/service";

  export default {
    name: "mallShops",
    data() {
      return {
        dialogVisible: false,
        modShops: false,
        page: 1,
        total: 0,
        listData: [],
        sellerName: ''
      }
    },
    mixins: [ajax],
    created() {
      this.getList();
    },
    methods: {
      getList() {
        this.doajax(sellerList, {page: this.page}, (resp) => {
          this.listData = resp.data;
          this.total = resp.total;
        })
      },
      dialogVisibleTrue() {
        this.doajax(addSeller, {sellerName: this.sellerName}, (resp) => {
          this.dialogVisible = false;
          this.success("添加成功");
          this.getList();
        })
      },
      modShopsTrue() {
        this.doajax(modifySellerName, {sellerId: this.sellerId, sellerName: this.sellerName}, (resp) => {
          this.modShops = false;
          this.success("修改成功");
          this.getList();
        })
      },

      open(row) {
        this.$confirm('确定删除吗?', '删除', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          let sellerId = row.sellerId;
          this.doajax(deleteSeller, {sellerId: sellerId}, (resp) => {
            this.getList();
            this.success("删除成功")
          })
        }).catch(() => {

        });
      },
      modShopsBtn(row) {
        this.sellerId = row.sellerId;
        this.sellerName = row.sellerName;
        this.modShops = true;
      },
      addShops() {
        this.dialogVisible = true;
        this.sellerName = '';
      },
      jump(val) {
        this.page = val;
        this.getList();
      },
    }
  }
</script>

<style scoped>

</style>
